/*
 * Copyright (C) 2013 Daniel Wasilew <daniel.wasilew@codeminer.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.codeminer.parts.database.derby;

import java.util.List;
import org.codeminer.database.DatabaseException;
import org.codeminer.parts.database.PlaylistConnector;
import org.codeminer.parts.database.dao.PlaylistDAO;
import org.codeminer.parts.library.Playlist;
import org.codeminer.parts.library.Song;
import org.codeminer.parts.server.users.User;

/**
 *
 * @author Daniel Wasilew <daniel.wasilew@codeminer.org>
 */
public class DerbyPlaylistStorageConnector extends DerbyStorageConnector implements PlaylistConnector {

    @Override
    public Playlist storePlaylist(Playlist playlist, User owner) throws DatabaseException {
        return PlaylistDAO.store(playlist, owner, getConnection());
    }

    @Override
    public boolean deletePlaylist(Playlist playlist) throws DatabaseException {
        return PlaylistDAO.delete(playlist, getConnection());
    }

    @Override
    public List<Playlist> findPlaylist(Playlist searchCriteria, User user) throws DatabaseException {
        return PlaylistDAO.get(searchCriteria, user, getConnection());
    }

    @Override
    public boolean updatePlaylist(Playlist playlist) throws DatabaseException {
        return PlaylistDAO.update(playlist, getConnection());
    }

    @Override
    public List<Song> getSongsForPlaylist(Playlist playlist) throws DatabaseException {
        return PlaylistDAO.getSongs(playlist, getConnection());
    }

    @Override
    public void addSongToPlaylist(Song song, Playlist playlist) throws DatabaseException {
        PlaylistDAO.addSongToPlaylist(playlist, song, getConnection());
    }

    @Override
    public void removeSongFromPlaylist(Song song, Playlist playlist) throws DatabaseException {
        PlaylistDAO.removeSongToPlaylist(playlist, song, getConnection());
    }

    @Override
    public List<Playlist> getPlaylists(User user) throws DatabaseException {
        return PlaylistDAO.get(user, getConnection());
    }

    @Override
    public Class getAccessorDescription() {
        return PlaylistConnector.class;
    }
    
    
}
